package com.maycurobj.controller.systembase;

import com.alibaba.fastjson.JSONObject;
import com.maycurobj.service.impl.BimService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 注意:全部迁移到dingtalkproject项目中,此接口服务不在使用
 * 系统相关的基础接口服务
 * 统一登录的用户信息接口
 */
@Controller
@RequestMapping("/base/userInfo")
@Slf4j
public class SystemUserInfoController {

    @Autowired
    private BimService bimService;


    /**
     * 获取钉钉 userids 迁移到dingtalkproject中
     * ids: xx,xx,xx
     *
     * @param jsonObject
     */
    @PostMapping("/getDingUserid")
    @ResponseBody
    @Deprecated
    public JSONObject getDingUseridByCrmuserid(@RequestBody JSONObject jsonObject) {
        JSONObject jsonObject1 = new JSONObject();
        try {
            if (Strings.isBlank(jsonObject.getString("ids"))) {
                jsonObject1.put("code",-1);
                jsonObject1.put("msg","参数异常");
                return jsonObject1;
            }else{
                String result = bimService.getDingUserIdByCrmworkcodes(jsonObject.getString("ids"));

                if (StringUtils.isBlank(result)) {
                    jsonObject1.put("code",-1);
                    jsonObject1.put("msg","参数异常");
                }else{
                    jsonObject1.put("code",1);
                    jsonObject1.put("msg",result);
                }
                log.info("请求-获取钉钉userid的结果:{}", jsonObject1.toJSONString());
                return jsonObject1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            jsonObject1.put("code",-100);
            jsonObject1.put("msg","参数异常");
            return null;
        }

    }

    @PostMapping("/getIamUsername")
    @ResponseBody
    @Deprecated
    public JSONObject getIamUsernameByDingId(@RequestParam("dingId") String dingId) {
        JSONObject jsonObject1 = new JSONObject();
        if (StringUtils.isBlank(dingId)) {
            jsonObject1.put("code", -100);
            jsonObject1.put("msg", "参数异常");

            return jsonObject1;
        }
        String username = bimService.getIamUsernameByDingId(dingId);
        if (StringUtils.isBlank(username)) {
            jsonObject1.put("code", -1);
            jsonObject1.put("msg", "找不到对应user name");
        }else{
            jsonObject1.put("code", 1);
            jsonObject1.put("msg", username);
        }
        return jsonObject1;
    }

    /**
     * 清除 奥哲所有待办
     */
    @PostMapping("/deleteIamTodoByAozhe")
    @ResponseBody
    @Deprecated
    public String deleteIamTodoByAozhe(){
        bimService.deleteIamTodoByAozhe();
        return "done";
    }
}
